#ifndef _STRAWGUI_OBSERVER_H_
#define _STRAWGUI_OBSERVER_H_

#include <vector>
#include "sEvents.h"

#define CAST_EVENT(var, type) const obs:: type & var = static_cast<const obs:: type &>(event)

namespace sgui
{
namespace obs
{

struct sEvent
{
	virtual const EEventId getID() const;
	virtual const EEventType getType() const;
};

class sObserver;


class sSubject
{
	
private:

	struct sSubjectObserver
	{
		sObserver*			m_observer;
		EEventTag			m_tag;

		bool operator==(const sSubjectObserver& other) 
		{
			return m_observer == other.m_observer;
		}
	};

	std::vector<sSubjectObserver>	m_observers;
public:
	void registerObserver(sObserver* observer, const EEventTag tag = EVTAG_ALL);
	void unregisterObserver(sObserver* observer, bool andRelease = false);
	void notify(sEvent* event, const EEventTag tag = EVTAG_ALL);
};

class sObserver
{
public:
	virtual bool OnEvent(const sEvent& event) = 0;
};

};
};

#endif